//
//  ModelUser.m
//  MexicoLoan
//
//  Created by WXP on 2025/2/24.
//
//

#import "ModelUser.h"

NSString *const kModelUserPhone  = KEY_phone;
NSString *const kModelUserUnused = KEY_unused;
//NSString *const kModelUserExtraAmountIsNotReminded = KEY_extraAmountIsNotReminded;
//NSString *const kModelUserRepaymentTotalAmount =     KEY_repaymentTotalAmount;
//NSString *const kModelUserRealName = KEY_realName;
NSString *const kModelUserRepaymentRemainAmount = KEY_repaymentRemainAmount;

@interface ModelUser ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ModelUser

@synthesize phone = _phone;
@synthesize unused = _unused;
//@synthesize extraAmountIsNotReminded = _extraAmountIsNotReminded;
//@synthesize repaymentTotalAmount = _repaymentTotalAmount;
//@synthesize realName = _realName;
@synthesize repaymentRemainAmount = _repaymentRemainAmount;

#pragma mark - init
+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
        self.phone = [self objectOrNilForKey:kModelUserPhone fromDictionary:dict];
        self.unused = [[self objectOrNilForKey:kModelUserUnused fromDictionary:dict] doubleValue];
//            self.extraAmountIsNotReminded = [[self objectOrNilForKey:kModelUserExtraAmountIsNotReminded fromDictionary:dict] boolValue];
//            self.repaymentTotalAmount = [[self objectOrNilForKey:kModelUserRepaymentTotalAmount fromDictionary:dict] doubleValue];
//            self.realName = [self objectOrNilForKey:kModelUserRealName fromDictionary:dict];
        self.repaymentRemainAmount = [[self objectOrNilForKey:kModelUserRepaymentRemainAmount fromDictionary:dict] doubleValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.phone forKey:kModelUserPhone];
    [mutableDict setValue:[NSNumber numberWithDouble:self.unused] forKey:kModelUserUnused];
//    [mutableDict setValue:[NSNumber numberWithBool:self.extraAmountIsNotReminded] forKey:kModelUserExtraAmountIsNotReminded];
//    [mutableDict setValue:[NSNumber numberWithDouble:self.repaymentTotalAmount] forKey:kModelUserRepaymentTotalAmount];
//    [mutableDict setValue:self.realName forKey:kModelUserRealName];
    [mutableDict setValue:[NSNumber numberWithDouble:self.repaymentRemainAmount] forKey:kModelUserRepaymentRemainAmount];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}

@end

